#!/bin/bash
###
 # @Author: dvlproad dvlproad@163.com
 # @Date: 2023-02-25 02:04:22
 # @LastEditors: dvlproad dvlproad@163.com
 # @LastEditTime: 2023-08-13 22:45:09
 # @FilePath: /AutoPackage-CommitInfo/bulidScriptCommon/brances_info/brances_info_log/test/tssh_branch_detail_info_result.sh
 # @Description: 测试分支本身的详情信息
### 

# 定义颜色常量
NC='\033[0m' # No Color
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'

# 当前【shell脚本】的工作目录
# $PWD代表获取当前路径，当cd后，$PWD也会跟着更新到新的cd路径。这个和在终端操作是一样的道理的
CurrentDIR_Script_Absolute="$( cd "$( dirname "$0" )" && pwd )"
#echo "CurrentDIR_Script_Absolute=${CurrentDIR_Script_Absolute}"
#CommonFun_HomeDir_Absolute3=${CurrentDIR_Script_Absolute}/..
CommonFun_HomeDir_Absolute3=${CurrentDIR_Script_Absolute%/*} # 使用此方法可以避免路径上有..
CommonFun_HomeDir_Absolute2=${CommonFun_HomeDir_Absolute3%/*}
CommonFun_HomeDir_Absolute=${CommonFun_HomeDir_Absolute2%/*}

qscript_path_get_filepath="${CommonFun_HomeDir_Absolute}/qscript_path_get.sh"
qbase_update_json_file_singleString_script_path="$(sh ${qscript_path_get_filepath} qbase update_json_file_singleString)"

qbase_function_log_msg_script_path="$(sh ${qscript_path_get_filepath} qbase function_log_msg)"
source $qbase_function_log_msg_script_path # 为了使用 logResultValueToJsonFile 、 logResultValueToJsonFile
echo "${YELLOW}引入文件： ${BLUE}${qbase_function_log_msg_script_path}${NC}"

get_all_branch_log_script_path="${CommonFun_HomeDir_Absolute}/brances_info/brances_info_log/get_all_branch_log.sh"


Develop_Branchs_FILE_PATH="${CurrentDIR_Script_Absolute}/data/test_data_branch_info.json"
TEST_DATA_RESULT_FILE_PATH="${CurrentDIR_Script_Absolute}/data/test_data_save_result.json"
Package_Environment_FILE_PATH="${CurrentDIR_Script_Absolute}/data/test_data_env_info.json"





function test_initLastAllChangeLog() {
    echo "----------------------------------------------------------------------------6最终方法:initLastAllChangeLog"
    echo "{}" > ${TEST_DATA_RESULT_FILE_PATH} #清空文件内容,但清空成{}
    # 设置执行命令的前提： 记录当前分支的文件路径、 历史分支路径、分支计算结果要保存的路径
    function updateEnvKeyStringValue() {
        EnvKey=$1
        EnvValue=$2
        #echo "正在执行命令(更新路径到JSON文件中)：《sh \"${qbase_update_json_file_singleString_script_path}\" -jsonF \"${Package_Environment_FILE_PATH}\" -k \"${EnvKey}\" -v \"${EnvValue}\"》"
        sh "${qbase_update_json_file_singleString_script_path}" -jsonF "${Package_Environment_FILE_PATH}" -k "${EnvKey}" -v "${EnvValue}"
        if [ $? != 0 ]; then
            exit 1
        fi
    }
    # updateEnvKeyStringValue "developBranchsJsonFile" "${Develop_Branchs_FILE_PATH}"
    
    History_Versions_FILE_PATH="${CurrentDIR_Script_Absolute}/data/test_data_history_version.json"
    # updateEnvKeyStringValue "historyVersionJsonFile" "${History_Versions_FILE_PATH}"
    
    # updateEnvKeyStringValue "branchsResultJsonFile" "${TEST_DATA_RESULT_FILE_PATH}"

    # # 正式执行命令：
    REQUEST_FOR_LOG_TYPE_ARRAY=("Notification" "Pgyer")
    echo "${YELLOW}正在执行命令(获取分支信息):《 sh ${get_all_branch_log_script_path} -envInfoF \"${Package_Environment_FILE_PATH}\" --request-for-log-types \"${REQUEST_FOR_LOG_TYPE_ARRAY[*]}\" -resultSaveToJsonF \"${TEST_DATA_RESULT_FILE_PATH}\" 》"
    sh ${get_all_branch_log_script_path} -envInfoF "${Package_Environment_FILE_PATH}" --request-for-log-types "${REQUEST_FOR_LOG_TYPE_ARRAY[*]}" -resultSaveToJsonF "${TEST_DATA_RESULT_FILE_PATH}"
    if [ $? != 0 ]; then
        exit 1
    fi

    #echo "------------6.1.①当前打包的所有分支信息如下:\n${FullChangeLogResult}"
    echo "------------6.1.②查看存入值，直接通过 cat 和 jquery"
    REQUEST_FOR_LOG_TYPE_COUNT=${#REQUEST_FOR_LOG_TYPE_ARRAY[*]}
    for((i=0;i<${REQUEST_FOR_LOG_TYPE_COUNT};i++));
    do
        REQUEST_FOR_LOG_TYPE_STRING=${REQUEST_FOR_LOG_TYPE_ARRAY[i]}
        # echo "----------------------------.branch_info_result.${REQUEST_FOR_LOG_TYPE_STRING}----------------------------"
        # cat ${TEST_DATA_RESULT_FILE_PATH} | jq ".branch_info_result.${REQUEST_FOR_LOG_TYPE_STRING}" | jq '.'
        echo "----------------------------.branch_info_result.${REQUEST_FOR_LOG_TYPE_STRING}.all.slice----------------------------"
        cat ${TEST_DATA_RESULT_FILE_PATH} | jq ".branch_info_result.${REQUEST_FOR_LOG_TYPE_STRING}.all.slice" | jq '.'
    done
    
    # echo "\n"
    # echo "----------------------------------------处理后文件最后的完整内容"
    # cat ${TEST_DATA_RESULT_FILE_PATH} | jq '.'
    
    echo "\n\n"

    echo "${YELLOW}更多详情请可点击查看文件: ${BLUE}${TEST_DATA_RESULT_FILE_PATH} ${NC}"
}





test_initLastAllChangeLog
